package com.artPreter.service.impl;

import com.artPreter.pojo.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.artPreter.mapper.ContentArtistRelativeMapper;
import com.artPreter.mapper.ArtistMapper;

import com.artPreter.pojo.dto.ArtistName;
import com.artPreter.pojo.dto.ItemBase;
import com.artPreter.service.IArtistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;



/**
 * <p>
 * 艺术家表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-11-14
 */
@Service
public class ArtistServiceImpl extends ServiceImpl<ArtistMapper, Artist> implements IArtistService {


    @Override
    public List<Artist> getRecommendArtists(int i) {
        List<Artist> result =new ArrayList<>();
        LambdaQueryWrapper<Artist> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Artist::getIsRecommend,1);
        queryWrapper.eq(Artist::getStatus,1);
        queryWrapper.last("limit "+i);
        if(i>0){
            result=this.baseMapper.selectList(queryWrapper);
        }
        return result;
    }

    @Override
    public List<Artist> getFamousArtists(int i) {
        List<Artist> result =new ArrayList<>();
        if(i>0){
            LambdaQueryWrapper<Artist> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Artist::getIsFamous,1);
            queryWrapper.orderByDesc(Artist::getFamousSort);
            queryWrapper.last("limit "+i );
            queryWrapper.eq(Artist::getStatus,1);
            result = this.baseMapper.selectList(queryWrapper);
        }
        return result;
    }

    @Override
    public List<Artist> getIndexArtists(int i) {
        List<Artist> result = new ArrayList<>();
        if(i>0){
            LambdaQueryWrapper<Artist> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Artist::getIsIndex,1);
            queryWrapper.orderByDesc(Artist::getIndexSort);
            queryWrapper.last("limit "+i );
            queryWrapper.eq(Artist::getStatus,1);
            result = this.baseMapper.selectList(queryWrapper);
        }
        return result;
    }

    @Override
    public List<Artist> getRelatedArtistList(DepartContentSection departContentSection) {
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",departContentSection.getContentId());
        List<Artist> result = this.baseMapper.getRelatedArtistList(artistQueryWrapper);
        return result;
    }

    @Override
    public Artist getArtist(String artistId) {
        LambdaQueryWrapper<Artist> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Artist::getArtistId,artistId);
        List<Artist> result = this.baseMapper.selectList(queryWrapper);
        if(result.size()>0){
            return result.get(0);
        }else{
            return null;

        }

    }

    @Override
    public List<Artist> getArtistByName(Artist artist) {
        LambdaQueryWrapper<Artist> queryWrapper = new LambdaQueryWrapper<>();
        // 拼音
        if(artist.getFirstPy()!=null&& !artist.getFirstPy().isEmpty() &&!artist.getFirstPy().equals("null")){
            queryWrapper.eq(Artist::getFirstPy,artist.getFirstPy());
        }
        // 名字
        if(artist.getName()!=null&&!artist.getName().equals("")){
            queryWrapper.like(Artist::getName,artist.getName());
        }
        // 艺术类型
        if(artist.getArtistType()!=null&&!artist.getArtistType().equals("")){
            queryWrapper.like(Artist::getArtistType,artist.getArtistType());

        }
        List<Artist> result = this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public IPage<Artist> getPage(Integer currentPage, Integer size, Artist artist) {
        LambdaQueryWrapper<Artist> queryWrapper = new LambdaQueryWrapper<>();
        // 状态
        queryWrapper.eq(Artist::getStatus,1);
        // 拼音
        if(artist.getFirstPy()!=null&& !artist.getFirstPy().isEmpty() &&!artist.getFirstPy().equals("null")){
            queryWrapper.eq(Artist::getFirstPy,artist.getFirstPy());
        }
        // 名字
        if(artist.getName()!=null&&!artist.getName().equals("")){
            queryWrapper.like(Artist::getName,artist.getName());
        }
        // 艺术类型
        if(artist.getArtistType()!=null&&!artist.getArtistType().equals("")){
            queryWrapper.like(Artist::getArtistType,artist.getArtistType());
        }
        IPage<Artist> artistIPage = new Page<>(currentPage,size);
        artistIPage = this.baseMapper.selectPage(artistIPage,queryWrapper);
        return artistIPage;
    }

    @Override
    public IPage<Artist> getRelatedArtistPageList(DepartContentSection departContentSection, Integer currentPage, Integer size) {
        IPage<Artist> artistIPage = new Page<>(currentPage,size);
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",departContentSection.getContentId());
        // 艺术家名字模糊搜索
        if(departContentSection.getSearchName()!=null&&!departContentSection.getSearchName().equals("")&&!departContentSection.getSearchName().equals("null")){
            artistQueryWrapper.like("b.name",departContentSection.getSearchName());
        }
        // 艺术家擅长类型搜索
        if(departContentSection.getSearchType()!=null&&!departContentSection.getSearchType().equals("")&&!departContentSection.getSearchType().equals("null")){
            artistQueryWrapper.like("b.artist_type",departContentSection.getSearchType());
        }
        artistQueryWrapper.orderByDesc("s.sort");
        artistQueryWrapper.isNotNull("b.id");
        artistIPage = this.baseMapper.getRelatedArtistPageList(artistIPage,artistQueryWrapper);
        return artistIPage;
    }

    @Override
    public Artist getArtistById(Integer id) {
        Artist artist = this.baseMapper.selectById(id);
        return artist;
    }

    @Override
    public IPage<Artist> getEventExhibitionRelatedArtistPageList(EventExhibitionContentSection eventExhibitionContentSection, Integer currentPage, Integer size) {
        IPage<Artist> artistIPage = new Page<>(currentPage,size);
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",eventExhibitionContentSection.getContentId());
        // 艺术家名字模糊搜索
        if(eventExhibitionContentSection.getSearchName()!=null&&!eventExhibitionContentSection.getSearchName().equals("")&&!eventExhibitionContentSection.getSearchName().equals("null")){
            artistQueryWrapper.like("b.name",eventExhibitionContentSection.getSearchName());
            System.out.println("模糊搜索名字");
        }
        // 艺术家擅长类型搜索
        if(eventExhibitionContentSection.getSearchType()!=null&&!eventExhibitionContentSection.getSearchType().equals("")&&!eventExhibitionContentSection.getSearchType().equals("null")){
            artistQueryWrapper.like("b.artist_type",eventExhibitionContentSection.getSearchType());
        }
        artistQueryWrapper.orderByDesc("s.sort");
        artistQueryWrapper.isNotNull("b.id");
        artistIPage = this.baseMapper.getRelatedArtistPageList(artistIPage,artistQueryWrapper);
        return artistIPage;
    }

    @Override
    public List<Artist> getEventExhibitionRelatedArtistList(EventExhibitionContentSection eventExhibitionContentSection) {
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",eventExhibitionContentSection.getContentId());
        List<Artist> result = this.baseMapper.getRelatedArtistList(artistQueryWrapper);
        return result;
    }

    @Override
    public List<ArtType> getRelatedArtistTypeList(DepartContentSection departContentSection) {
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",departContentSection.getContentId());
        // 艺术家名字模糊搜索
        if(departContentSection.getSearchName()!=null&&!departContentSection.getSearchName().equals("")&&!departContentSection.getSearchName().equals("null")){
            artistQueryWrapper.like("b.name",departContentSection.getSearchName());
        }
        // 艺术家擅长类型搜索
        if(departContentSection.getSearchType()!=null&&!departContentSection.getSearchType().equals("")&&!departContentSection.getSearchType().equals("null")){
            artistQueryWrapper.like("b.artist_type",departContentSection.getSearchType());
        }


        return null;
    }

    @Override
    public List<ArtType> getDepartRelatedArtistTypeList(DepartContentSection departContentSection) {
        List<ArtType> result = new ArrayList<>();
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",departContentSection.getContentId());
        // 艺术家名字模糊搜索
        if(departContentSection.getSearchName()!=null&&!departContentSection.getSearchName().equals("")&&!departContentSection.getSearchName().equals("null")){
            artistQueryWrapper.like("b.name",departContentSection.getSearchName());
        }
        artistQueryWrapper.isNotNull("b.id");
        result = this.baseMapper.getDepartRelatedArtistTypeList(artistQueryWrapper);
        return result;
    }

    @Override
    public List<ArtType> getEventRelatedArtistTypeList(EventExhibitionContentSection eventExhibitionContentSection) {
        List<ArtType> result = new ArrayList<>();
        QueryWrapper<Artist> artistQueryWrapper = new QueryWrapper<>();
        artistQueryWrapper.eq("s.content_id",eventExhibitionContentSection.getContentId());
        // 艺术家名字模糊搜索
        if(eventExhibitionContentSection.getSearchName()!=null&&!eventExhibitionContentSection.getSearchName().equals("")&&!eventExhibitionContentSection.getSearchName().equals("null")){
            artistQueryWrapper.like("b.name",eventExhibitionContentSection.getSearchName());
            System.out.println("模糊搜索名字");
        }
        // 艺术家擅长类型搜索
        if(eventExhibitionContentSection.getSearchType()!=null&&!eventExhibitionContentSection.getSearchType().equals("")&&!eventExhibitionContentSection.getSearchType().equals("null")){
            artistQueryWrapper.like("b.artist_type",eventExhibitionContentSection.getSearchType());
        }
        artistQueryWrapper.isNotNull("b.id");
        result = this.baseMapper.getEventRelatedArtistTypeList(artistQueryWrapper);
        return result;
    }


}
